#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

import os
import torch
import numpy as np


def edge_dilate_hor_c1(input_image, width, height):
    output = np.zeros_like(input_image)
    output[:2, :] = 0
    output[-2:, :] = 0
    top = input_image[1:-3]
    center = input_image[2:-2]
    bottom = input_image[3:-1]
    dilated = np.maximum(top, np.maximum(center, bottom))
    output[2:-2, :] = dilated
    return output


def threshol8u(img, width, height):
    return np.where(img != 0, 1, 0).astype(np.uint8)


def gen_golden_data_simple():

    dtype = np.uint8
    width, height = 4887, 3440
    input_shape = [height, width]
    
    img = np.random.randint(0, 256, input_shape).astype(dtype)
    
    golden1 = edge_dilate_hor_c1(img, width, height)
    golden = threshol8u(golden1, width, height)

    os.system("mkdir -p input")
    os.system("mkdir -p output")
    img.astype(dtype).tofile("./input/input_img.bin")
    golden.tofile("./output/golden.bin")

if __name__ == "__main__":
    gen_golden_data_simple()

